package com.datastructure.test.numnodeofentiretree;

public class NumNodeOfEntireTree {

    public static void main(String[] args) {

    }

    public int nodeNum(TreeNode head) {
        int depthOfTree = getDepthOfTree(head);
        return depthOfTree;
    }

    public int getDepthOfTree(TreeNode head){
        if(head==null){
            return 0;
        }
        int sum=0;
        if(head.left!=null){
            sum+=getDepthOfTree(head.left);
        }
        if(head.right!=null){
            sum+=getDepthOfTree(head.right);
        }
        return sum+1;
    }
}

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }
}
